const app = getApp();
var utils = require('../../../utils/util');
var loadMoreView,p = 1,num = 10,type='service'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        selectIndex:0,
        array:["好评优先","距离优先","人气优先",""],
        homemakingServiceList:[]
    },
    makeCall(e){
        let phone = e.currentTarget.dataset.phone;
        wx.makePhoneCall({
            phoneNumber:phone
        })
    },
    goToDetails:function(e){
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url:'/subPages/communityService/pharmacyDetails/pharmacyDetails?id='+id
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let that = this;
        loadMoreView = this.selectComponent("#loadMoreView")
        utils.setNavBarTitle('药店');
        this.getHomemakingService();
    },
    getHomemakingService(){
        var that = this;
        let type = that.data.type,url;
        utils.getAjax(`${app.globalData.apiUrl}/get_community_service_pharmacy`,function(res){
            console.log(res);
            if(res.data.list.length != 0){
                var list = [];
                if(p == 1){
                    list = res.data.list
                }else{
                    list = that.data.homemakingServiceList.concat(res.data.list)
                }
                that.setData({
                    homemakingServiceList:list
                })
            }else{
                that.setData({
                    homemakingServiceList:[]
                })
            }
            loadMoreView.loadMoreComplete(res.data,type)
        },{
            p:p,
            num:num,
            community_id:app.globalData.communityId
        })
    },
    //获取服务数据异常
    shopDataErr(err){
        if(p>1){
            loadMoreView.loadMoreFail()
        }else{
            util.showModal('提示','获取商品失败，请向上滑动屏幕')
            this.setData({
                isFail: true
            })
        }
    },
    loadMoreListener: function(e) {
        p += 1
        this.getHomemakingService()
    },

    clickLoadMore: function(e) {
        this.getHomemakingService()
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        if(this.data.isFail){
            this.getHomemakingService()
            return
        }
        loadMoreView.loadMore()
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})
